//https://leetcode.cn/problems/minimum-time-to-complete-trips/submissions/565927890/
class Solution {
public:
    long long minimumTime(vector<int> &time, int totalTrips) {
        using ll = long long;
        auto f = [&](ll x) -> bool {
            ll sum = 0;
            for (int t : time) {
                sum += x / t;
                if (sum >= totalTrips) 
                    return true;
            }
            return false;
        };
        ll mi = ranges::min(time),
            left = mi - 1,
            right = totalTrips * mi; 
        while (left + 1 < right) {
            ll mid = (left+right)>>1;
            (f(mid) ? right : left) = mid;
        }
        return right; 
    }
};